package com.canaan.business.controller.pc.storehouse;

import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.business.domain.storehouse.TacticConfig;
import com.canaan.business.service.storehouse.ITacticConfigService;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * 库存配置策略Controller
 *
 * @author ruoyi
 * @date 2023-02-24
 */
@Api(tags = "库存配置策略")
@RestController
@RequestMapping("/tactic/config")
public class TacticConfigController extends BaseController {
    @Resource
    private ITacticConfigService tacticConfigService;

    /**
     * 查询库存配置策略列表
     */
    @ApiOperation(value = "查询库存配置策略列表")
    @GetMapping("/list")
    public TableDataInfo list(TacticConfig tacticConfig) {
        startPage();
        List<TacticConfig> list = tacticConfigService.selectTacticConfigList(tacticConfig);
        return getDataTable(list);
    }

    /**
     * 导出库存配置策略列表
     */
    @ApiOperation(value = "导出库存配置策略列表")
    @Log(title = "库存配置策略", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TacticConfig tacticConfig) {
        List<TacticConfig> list = tacticConfigService.selectTacticConfigList(tacticConfig);
        ExcelUtil<TacticConfig> util = new ExcelUtil<TacticConfig>(TacticConfig.class);
        util.exportExcel(response, list, "库存配置策略数据");
    }

    /**
     * 获取库存配置策略详细信息
     */
    @ApiOperation(value = "获取库存配置策略详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tacticConfigService.selectTacticConfigById(id));
    }

    /**
     * 新增库存配置策略
     */
    @ApiOperation(value = "新增库存配置策略")
    @Log(title = "库存配置策略", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TacticConfig tacticConfig) {
        return toAjax(tacticConfigService.insertTacticConfig(tacticConfig));
    }

    /**
     * 修改库存配置策略
     */
    @ApiOperation(value = "修改库存配置策略")
    @Log(title = "库存配置策略", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TacticConfig tacticConfig) {
        return toAjax(tacticConfigService.updateTacticConfig(tacticConfig));
    }

    /**
     * 删除库存配置策略
     */
    @ApiOperation(value = "删除库存配置策略")
    @Log(title = "库存配置策略", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tacticConfigService.deleteTacticConfigByIds(ids));
    }
}
